//SPU管理模块接口
import request from "@/utils/request";
//导入相关类型
import type { SkuData, HasSpuResponseData, AllTradeMark, SkuInfoData, SpuHasImg, HasSaleAttrResponseData, SaleAttrResponseData, SpuData } from "./type";

enum API {
    //获取已有的SPU的数据
    HASSPU_URL = '/admin/product/',
    //获取全部品牌的数据
    ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
    //获取某个SPU下的全部的照片链接
    IMAGE_URL = '/admin/product/spuImageList/',
    //获取某一个SPU下的全部已有的销售属性
    SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    //获取整个项目的所有销售属性[颜色,版本,尺码]
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
    //追加一个新的SPU
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    //更新已有的SPU
    UPDATESPU_URL = '/admin/product/saveSpuInfo',
    //追加一个新的SKU
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    //查看某个SPU下的SKU目录
    SKUINFO_URL = '/admin/product/findBySpuId/',
    //删除已有的SPU
    DELETESPU_URL = '/admin/product/deleteSpu/'
}

// 获取某个三级分类下已有的SPU数据
export const reqHasSpu = (page: number, limit: number, category3Id: string | number) => request.get<any, HasSpuResponseData>(API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`)
//获取全部的SPU品牌的数据
export const reqAllTradeMark = () => request.get<any, AllTradeMark>(API.ALLTRADEMARK_URL)
//获取一个指定的已有SPU下全部商品的图片地址
export const reqAllImage = (spuId: number) => request.get<any, SpuHasImg>(API.IMAGE_URL + spuId)
//获取某个spu下的销售属性
export const reqSpuHasSaleAttr = (spuId: number) => request.get<any, SaleAttrResponseData>(API.SPUHASSALEATTR_URL + spuId)
//获取全部的销售属性
export const reqAllSaleAttr = () => request.get<any, HasSaleAttrResponseData>(API.ALLSALEATTR_URL)


//添加和修改
export const reqAddOrUpdate = (data: SpuData) => {
    //有id则证明是更新,没有则证明是新增
    if (data.id) {
        //更新SPU
        console.log(123)
        return request.post<any, any>(API.UPDATESPU_URL, data)
    } else {
        //添加SPU
        return request.post<any, any>(API.ADDSPU_URL, data)
    }
}

//添加SKU的方法
export const reqAddSku = (data: SkuData) => request.post<any, any>(API.ADDSKU_URL, data)

//获取SKU的数据
export const getSkuList = (skuId: number | string) => request.get<any, SkuInfoData>(API.SKUINFO_URL + skuId)

//删除已有的SPU
export const deleteSpu = (spuId: number | string) => request.delete<any, any>(API.DELETESPU_URL + spuId)